package com.lc.app.androidfirst.userdefine.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.lc.app.androidfirst.R;

public class ForResultActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_for_result);


        Button btn1 = (Button) findViewById(R.id.testResultButton1);
        Button btn2 = (Button) findViewById(R.id.testResultButton2);
        Button btn3 = (Button) findViewById(R.id.testResultButton3);
        Button btn4 = (Button) findViewById(R.id.testResultButton4);
        Button btn5 = (Button) findViewById(R.id.testResultButton5);

        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int resultCode = 0;
                String key = "data";
             //   Bundle bundle = new Bundle();
                EditText editText = (EditText) findViewById(R.id.testResultEditText);
                int id = v.getId();
                if(id == R.id.testResultButton1 || id == R.id.testResultButton3){
                    resultCode = 1;
                }else if(id == R.id.testResultButton2 || id == R.id.testResultButton4){
                    resultCode = 2;
                }else {
                    resultCode = 3;
                }

                Intent intent = getIntent();
                intent.putExtra(key,editText.getText().toString());
                ForResultActivity.this.setResult(resultCode, intent);
                ForResultActivity.this.finish();
            }
        };


        btn1.setOnClickListener(listener);
        btn2.setOnClickListener(listener);
        btn3.setOnClickListener(listener);
        btn4.setOnClickListener(listener);
        btn5.setOnClickListener(listener);


    }

}
